# 03-ATM.py
# 读取文件余额
def get_file():
     with open('./11-money.txt','r',encoding="utf-8") as file:
          str = file.read()
     return str
# 查询余额
def get_money(name):
    print('----------查询余额---------')
    print(f"{name}，您好，您的余额剩余{get_file()}RMB")
# 存款
def add_money(name):
      print('----------存款---------')
      a = int(input("请输入存款金额:"))
      money = int(get_file())+ a
      with open('./11-money.txt','w')as file:
           file.write(str(money))
      print(f'存款金额为{a}RMB')
      print(f'{name},你好，你的余额为{get_file()}RMB')
# 取款
def update_money(name):
      print('----------取款---------')
      a = int(input('请输入取款金额：'))
     
      if a<int(get_file()):
          money = int(get_file())-a 
          with open('./11-money.txt','w')as file:
               file.write(str(money))
          print(f'取款金额为{a}RMB')
          print(f'{name}，你好，您的余额为{get_file()}RMB')
      else:
          print('都没钱了，还取啥')
# 主菜单
def main(name):
    print('------------主菜单---------')
    print(f"{name},你好，欢迎来到农商银行ATM,请选择操作：")
    while True:
        print('查询余额',"[输入1]")
        print('存款\t',"[输入2]")
        print('取款\t',"[输入3]")
        print("退出\t","[输入4]")
        index = input('请输入您的选择：')
        if index=="4":break
        if index=="1":get_money(name)
        if index=="2":add_money(name)
        if index=="3":update_money(name)
main(input('请输入姓名：'))